/*
 * rtc_hal.h
 *
 * Created: 8/16/2013 9:48:59 AM
 *  Author: Ken Arok
 
 *      Revision history:
 *      ---------------------------------------------------------
 *      Date			|	Revised by		|	Description
 *      ---------------------------------------------------------
 *      1. Aug 16, 2013	|	Yosef			| New establishment
 *
 *
 *
 * \brief Hardware Abstraction Layer of RTC PCF8563.
 *
 * Copyright (c) 2013 PT Hanindo Automation Solutions. All rights reserved.
 *
 */

#include "config_board.h"

#if BOARD_1_0_USED

#ifndef RTC_HAL_H_
#define RTC_HAL_H_


#include <compiler.h>

#ifdef __cplusplus
extern "C" {
#endif

// TWI data transfer rate
#define TWI_SPEED						100000
// TWI RTC Slave Address
#define TWI_RTC_SLAVE_ADDRESS			(0xA2 >> 1)	//! PCF8563 Slave Address

// PFC8563 RTC Memory Address
#define VL_SECOND_ADDR		0x02
#define MINUTES_ADDR		0x03
#define HOURS_ADDR			0x04
#define DAYS_ADDR			0x05
#define WEEKDAYS_ADDR		0x06
#define CENTURY_MONTH_ADDR	0x07
#define YEARS_ADDR			0x08
#define CLKOUT_CTRL_ADDR	0x0D
#define TIMER_CTRL_ADDR		0x0E

/* Reset value of register. */
#define TIMER_CTRL_REG_DEF	0x03

typedef struct {
	uint8_t seconds;
	uint8_t minutes;
	uint8_t hours;
	uint8_t days;
	uint8_t weekdays;
	uint8_t months;
	uint8_t years;
}rtc_raw_t;



/** \brief Write calender value to RTC chip register.
 *
 * \param _rtc	Pointer to RTC raw structure.
 *
 */
extern void rtc_write_calendar(rtc_raw_t *_rtc);

/** \brief Read calender value from RTC chip register.
 *
 * \param _rtc	Pointer to RTC raw structure where RTC value will be copied.
 *
 */
extern void rtc_read_calendar(rtc_raw_t *_rtc);

/** \brief Read the CTRL status register of PCF8563.
 *
 * \return CTRL_VAL		Value of CTRL register.
 *
 */
extern uint8_t rtc_read_ctrl(void);

#ifdef __cplusplus
}
#endif

#endif /* RTC_HAL_H_ */

#endif /* BOARD_1_0_USED */
